package org.ihelpuoo.orm.handler;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;

import org.ihelpuoo.lang.ObjectUtils;
import org.ihelpuoo.orm.ObjectRule;
import org.ihelpuoo.orm.filter.FieldFilter;

public abstract class SaveListFieldhandler extends SaveCollectionFieldHandler
{

	public SaveListFieldhandler(ObjectProcessor beanHandler)
	{
		super(beanHandler);
	}

	@Override
	protected void processWithoutExceptionHandle(ObjectRule br, Field f, Object src, Object obj,
			FieldFilter actived, FieldFilter locked, String prefix) throws Exception
	{
		Method getter = ObjectUtils.getGetter(obj.getClass(),f);
		List v = (List)getter.invoke(obj,(Object[])null);
		if (null == v || v.size() == 0)
			return;

		Object subSrc = prepareSubSource(br,f,src);
		Iterator it = v.iterator();
		while (it.hasNext())
		{
			processor.insert(processor.manual.getRule(v.get(0).getClass()),subSrc,it.next(),null,
					null);
		}
	}

}
